package com.codeoss.framework.db.column;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Date;

import org.springframework.stereotype.Service;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.data.metadata.Column;

@Service
public class TimeColumnService implements IColumnService {

	@Override
	public Object getValue(YunContext yunContext, Column column, ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return rs.getTime(column.getColumnName());
	}

	@Override
	public void setValue(YunContext yunContext, Column column, PreparedStatement ps, int index, Object value)
			throws SQLException {
		// TODO Auto-generated method stub
		if(value==null){
			ps.setObject(index,value);
		}else if(value instanceof Date){
			Time time=new Time(((Date)value).getTime());
			ps.setTime(index, time);
		}else{
			ps.setTime(index,(Time)value);
		}
	}

}
